@inject('storeService', 'App\App\Services\StorageService')
@inject('VoteCandidate', 'App\Models\VoteCandidate\VoteCandidate')

@php
    if(empty($activity->rule)){
        $rule=[
            'repeatedOn'=>0,
            'enrollPayOn'=>0,
            'enrollPay'=>0,
            'upContentOn'=>0,
            'upContentType'=>0,
            'upContentNum'=>0,
            'showEnrollNumberOn'=>0
            ];
    }else{
        $rule = json_decode($activity->rule,true);

        $rule['repeatedOn'] = isset($rule['repeatedOn'])?$rule['repeatedOn']:0;
        $rule['enrollPayOn'] = isset($rule['enrollPayOn'])?$rule['enrollPayOn']:0;
        $rule['enrollPay'] = isset($rule['enrollPay'])?$rule['enrollPay']:0;
        $rule['upContentOn'] = isset($rule['upContentOn'])?$rule['upContentOn']:0;
        $rule['upContentType'] = isset($rule['upContentType'])?$rule['upContentType']:0;
        $rule['upContentNum'] = isset($rule['upContentNum'])?$rule['upContentNum']:0;
        $rule['showEnrollNumberOn'] = isset($rule['showEnrollNumberOn'])?$rule['showEnrollNumberOn']:0;
    }
    if (!empty($activity->shares)){
        $share = json_decode($activity->shares,true);
        $share['isopen'] = isset($share['isopen'])?$share['isopen']:0;
        $share['title'] = isset($share['title'])?$share['title']:0;
        $share['content'] = isset($share['content'])?$share['content']:0;
        $share['thumb'] = isset($share['thumb'])?$share['thumb']:'';
    }else{
        $share = ['isopen'=>0,'title'=>'','content'=>'','thumb'=>''];
    }
@endphp
<link rel="stylesheet" href="/css/CSS/main.css"/>
<div class="text-left">
    <ul class="nav nav-icons enroll-ul" role="tablist">
        <li class="active">
            <a href="#activity_tab_0" role="tab" data-toggle="tab" aria-expanded="true">
                内容设置
            </a>
        </li>
        <li ng-class="{'disabled':!activity_id}">
            <a href="#activity_tab_1" role="tab" data-toggle="tab" aria-expanded="true">
                报名设置
            </a>
        </li>
        <li ng-class="{'disabled':!activity_id}">
            <a href="#activity_tab_2" role="tab" data-toggle="tab" aria-expanded="true">
                渠道配置
            </a>
        </li>
        <li ng-class="{'disabled':!activity_id}">
            <a href="#activity_tab_3" role="tab" data-toggle="tab" aria-expanded="true">
                自定义设置
            </a>
        </li>
    </ul>
</div>
<div class="tab-content">
    <div class="tab-pane active" id="activity_tab_0">
        <div class="card">
            <div class="content">
                {{--<form id="enrollContentForm" class="form-horizontal" >--}}
                <div class="form-group">
                    <label class="col-md-2 control-label">活动名称</label>
                    <input type="hidden" name='' value="" id="activity_demoid"/>
                    <div class="col-md-7">
                        <input type="hidden" name="action" value="{{$ativity_model->rule}}"/>
                        <input class="form-control" type="text" ng-model="activity.name" value="{{$activity->name}}"
                               name="name" placeholder="请输入活动名称" maxlength="20"
                        />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">活动时间</label>
                    <div class="col-md-7">
                        <div class="row service-charges">
                            <div class="col-md-5 service-charges-name service-charges-name-0"
                                 style="padding-left: 15px;">
                                <input type="text" placeholder="开始时间" name="startTime" data-msg="请输入开始时间"
                                       value="{{$activity->startTime}}" class="form-control datetimepicker">
                            </div>
                            <div class="col-md-5 service-charges-remark service-charges-remark-0">
                                <input type="text" placeholder="结束时间" data-msg="请输入结束时间" name="endTime"
                                       value="{{$activity->endTime}}" class="form-control datetimepicker">
                            </div>

                        </div>
                    </div>
                </div>

                <div class="form-group backgroundImg-container">
                    <label class="col-md-2 control-label">更换背景</label>
                    <div class="col-md-7">
                        <input type="file" name="upfile" accept="image/gif,image/jpeg,image/png"
                               data-target="uploadImageFile" data-for="backgroundImg" data-preview-file-type="text"
                               class="form-control" value="" title="">
                        <input type="hidden" ng-model="activity.previewData.background" name="backgroundImg"
                               data-preview="{{$storeService->tomedia($activity->backgroundImg)}}"
                               value="{{$activity->backgroundImg}}">
                        <span class="help-block">支持PNG、JPG格式，尺寸640*264,小于200KB(建议无损后压缩再上传)</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">活动规则</label>
                    <div class="col-md-7">
                        <textarea class="form-control tinymceEditor"
                                  name="description">{{$activity->description}}</textarea>
                    </div>
                </div>
                {{--</form>--}}
            </div>
            <div class="footer  pull-center">
                <button type="button" class="btn btn-info btn-fill btn-wd"
                        ng-click="onFinishContent()">保存
                </button>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <div class="tab-pane" id="activity_tab_1">
        <div class="card">
            <div class="content">
                <div class="form-group">
                    <label class="col-md-2 control-label">是否显示报名人数</label>
                    <div class="col-md-7">
                        <div class="switch" id="switch-enroll-number-show" data-on-label="<i class='fa fa-check'></i>"
                             data-off-label="<i class='fa fa-times'></i>" data-on-color="success">
                            <input type="checkbox" name="rule[showEnrollNumberOn]"/>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">内容上传</label>
                    <div class="col-md-7">
                        <div class="switch" id="switch-enroll-upload" data-on-label="<i class='fa fa-check'></i>"
                             data-off-label="<i class='fa fa-times'></i>" data-on-color="success">
                            <input type="checkbox" name="rule[upContentOn]"/>
                        </div>
                        {{--<div style="visibility: hidden">--}}
                        {{--<input type="checkbox" name="rule[upContentOn]" value="0">--}}
                        {{--</div>--}}
                    </div>
                </div>
                <div class="div-enroll-upload mb15" style="display: none">
                    <div class="row">
                        <div class="col-sm-12 col-md-12 col-md-offset-2 col-sm-offset-2 mb15">
                            <label class="radio-inline">
                                <input type="radio" name="rule[upContentType]" value="image"
                                       class="enroll-upload-picture"> 图片
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="rule[upContentType]" value="video"
                                       class="enroll-upload-video"> 视频
                            </label>
                            {{--<label class="radio-inline">--}}
                            {{--<input type="radio" name="rule[upContentType]" value="voice" class="enroll-upload-audio" > 音频--}}
                            {{--</label>--}}
                        </div>
                    </div>
                    <div class="row">
                        <span class="col-sm-2 col-md-2 col-md-offset-1 col-sm-offset-1 control-label">最多上传</span>
                        <div class="col-sm-5 col-md-6">
                            <input class="form-control input-enroll-upload" name="rule[upContentNum]" type="number"
                                   min="1" data-msg="请输入大于等于1的数字"/>
                        </div>
                        <span class="col-sm-2 col-md-2 control-label" style="text-align:left">个内容</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">默认字段</label>
                    <div class="col-md-7">
                        <label class="checkbox-inline">
                            <input type="checkbox" name="rule[defaultName]" checked onclick="return false;" value="on">
                            姓名
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="rule[defaultMobile]" checked onclick="return false;"
                                   value="on"> 手机号
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">自定义字段</label>
                    <div class="col-md-9 enroll-self-group">
                        {{--自定义字段添加到按钮--}}
                        <div class="vote-group-card enroll-self-group-addButton"
                             style="padding-bottom: 50px !important">
                            <div class="pull-left enroll-self-group-type">
                                <label class="radio-inline">
                                    <input type="radio" name="enroll-self-type" class="enroll-upload-picture"
                                           value="radio"> 单选
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="enroll-self-type" class="enroll-upload-video"
                                           value="select"> 多选
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="enroll-self-type" class="enroll-upload-audio"
                                           value="selectdown"> 下拉
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="enroll-self-type" value="text"> 单行文本
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="enroll-self-type" value="textarea">多行文本
                                </label>
                                {{--<label class="radio-inline">--}}
                                {{--<input type="radio" name="enroll-self-type" value="upload"> 上传控件--}}
                                {{--</label>--}}
                            </div>
                            <div class="pull-right mgud add-vote-group">
                                <button type="button"
                                        class="btn btn-info add-vote-group-butten"
                                >
                                    +新建
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                {{--</form>--}}
            </div>
            <div class="footer  pull-center">
                <button type="button" class="btn btn-info btn-fill btn-wd"
                        ng-click="onFinishEnroll()">保存
                </button>
            </div>
        </div>
    </div>
    <div class="tab-pane" id="activity_tab_2">
        <div class="card">
            <div class="content">
                <div class="text-group">
                    <label>发布到APP</label>
                    <div class="switch has-switch" id="switch-enroll-app" data-on-label="是"
                         data-off-label="否" data-on-color="success">
                        <div class="switch-animate"
                             ng-class="{'switch-on':channel.app.is_open=='on', 'switch-off': channel.app.is_open=='off'}">
                            <span class="switch-left" ng-click="channel.app.is_open='off'">是</span>
                            <label ng-click="channel.app.is_open=='off'?channel.app.is_open='on':channel.app.is_open='off'">&nbsp;</label>
                            <span class="switch-right" ng-click="channel.app.is_open='on'">否</span>
                        </div>
                        <input type="hidden" name="app[is_open]" ng-value="channel.app.is_open" ng-model="channel.app.is_open"/>
                    </div>
                </div>
                <div class="form-group app" ng-if="channel.app.is_open=='on'">
                    <label class="col-md-2 control-label">APP下载链接</label>
                    <div class="col-md-7">
                        <input class="form-control app_url" type="text" name="app[app_urls][0]"
                               placeholder="配置app下载链接" ng-model="channel.app.app_urls[0]"/>
                    </div>
                </div>
                <div class="text-group">
                    <label>发布到微信</label>
                    <div class="switch has-switch" id="switch-enroll-wechat" data-on-label="是"
                         data-off-label="否" data-on-color="success">
                        <div class="switch-animate"
                             ng-class="{'switch-on':channel.wechat.is_open=='on', 'switch-off': channel.wechat.is_open=='off'}">
                            <span class="switch-left" ng-click="toggleClass($event,'off')">是</span>
                            <label ng-click="toggleClass($event,'label')">&nbsp;</label>
                            <span class="switch-right" ng-click="toggleClass($event,'on')">否</span>
                        </div>
                        <input type="hidden" name="wechat[is_open]" ng-value="channel.wechat.is_open" ng-model="channel.wechat.is_open"/>
                    </div>
                </div>
                <div class="form-group wechat" ng-if="channel.wechat.is_open=='on'">
                    <div class="form-group backgroundImg-container">
                        <label class="col-md-2 control-label">上传二维码</label>
                        <div class="file-wrap col-md-7">
                            <input ng-model="channel.wechat.qr_code[0]" class="fileInput ngFileInput" refresh="refresh"
                                   file-config="fileConfig" type="file" multiple="multiple" name="upfile"
                                   accept="image/gif,image/jpeg,image/png"
                                   data-target="uploadImageFiles" data-preview-file-type="text" value="" title="">
                            <span class="help-block mb0">支持PNG、JPG格式，小于200KB</span>
                        </div>
                    </div>
                    <input type="hidden" name="wechat[qr_code][0]" ng-value="channel.wechat.qr_code[0]" ng- ng-model="channel.wechat.qr_code[0]"/>
                </div>
                <hr/>
                <div class="form-group">
                    <label class="col-md-2 control-label">开启分享</label>
                    <div class="col-md-7">
                        <div class="switch" id="switch-enroll-share" data-on-label="是" data-off-label="否"
                             data-on-color="success">
                            <input type="checkbox" name="share[isopen]">
                        </div>
                    </div>
                </div>
                <div class="div-enroll-self" style="display: none">
                    <div class="form-group">
                        <label class="col-md-2 control-label">分享标题</label>
                        <div class="col-md-7">
                            <input class="form-control input-enroll-self-title" type="text" maxlength="15"
                                   name="share[title]" placeholder="最多15个字" data-msg="最多只能输入15个字符"
                            />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">分享文案</label>
                        <div class="col-md-7">
                                <textarea class="form-control input-enroll-self-inf" rows="5" maxlength="50"
                                          name="share[content]" placeholder="最多50个字" data-msg="最多只能输入50个字符"
                                ></textarea>
                        </div>
                    </div>
                    <div class="form-group backgroundImg-container">
                        <label class="col-md-2 control-label">分享图片</label>
                        <div class="col-md-7">
                            <input type="file" name="upfile" accept="image/gif,image/jpeg,image/png"
                                   data-target="uploadImageFile" data-for="share[thumb]" data-preview-file-type="text"
                                   class="form-control" value="" title="">
                            <input type="hidden" ng-model="activity.shares.thumb" name="share[thumb]"
                                   data-preview="{{$storeService->tomedia($share['thumb'])}}"
                                   value="{{$share['thumb']}}">
                            <span class="help-block">支持PNG、JPG格式，小于200KB</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="footer  pull-center">
                <button type="button" class="btn btn-info btn-fill btn-wd"
                        ng-click="onFinishConfig()">保存
                </button>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <div class="tab-pane" id="activity_tab_3">
        <div class="card">
            <div class="content">
                <div class="form-group backgroundImg-container">
                    <label class="col-md-2 control-label">列表背景</label>
                    <div class="col-md-7">
                        <input type="file" name="upfile" accept="image/gif,image/jpeg,image/png"
                               data-target="uploadImageFile" data-for="listBackgroundImg" data-preview-file-type="text"
                               class="form-control" value="" title="">
                        <input type="hidden" ng-model="activity.previewData.background" name="listBackgroundImg"
                               data-preview="{{$storeService->tomedia($activity->listBackgroundImg)}}"
                               value="{{$activity->listBackgroundImg}}">
                        <span class="help-block">支持PNG、JPG格式，小于200KB</span>
                    </div>
                </div>
            </div>
            <div class="footer pull-center">
                <button type="button" class="btn btn-info btn-fill btn-wd"
                        ng-click="onFinishSelf()">保存
                </button>
            </div>
        </div>
    </div>
</div>
<script src="/js/admin/initUploadImageSize.js"></script>
<script type="text/javascript">

    initUploadImageSize('.backgroundImg-container');
    initTinymce();
    initDatetimepicker();

    initDatetimepicker('#vote_act_time');
    initTimepicker();
    initColorPickerAndSwitch();
    console.log('ffff');

    require(['angular', 'directives'], function (angular) {
        var app = angular.module('app', ['directives','ngPlugin']);
        app.controller('subscriptionModalController',['$scope','$timeout','$http','$modalInstance','notify','items',function ($scope,$timeout,$http,$modalInstance,notify,items) {
            var profile = JSON.parse($('meta[name="profile"]').attr('content'));
            if(items.isAuthorize==1){
                $scope.postData = items.authorize;
            }else{
                $scope.postData = {
                    app_id: '',
                    app_secret: '',
                    group_code: profile.group_code,
                }
            }
            $scope.ok = function ($event) {
                if(!$scope.postData.app_id){
                    notify('APP_ID不能为空', 3);
                    return;
                }
                if(!$scope.postData.app_secret){
                    notify('SecurityKey不能为空', 3);
                    return;
                }
                var $btn = angular.element($event.target).addClass('disabled');
                $http({
                    method:items.isAuthorize==1?'PATCH':'POST',
                    url: '/web-api/configurations/wechat',
                    headers: JSON.parse($('meta[name="profile"]').attr('content')),
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                    data: $scope.postData,
                }).success(function (data) {
                    $btn.removeClass('disabled');
                    if (data.code == 200) {
                        if(items.isAuthorize==0){
                            notify('授权成功', 2);
                        }else{
                            notify('修改成功', 2);
                        }
                        $modalInstance.close($scope.postData);
                    } else {
                        notify(data.message, 3);
                    }
                }).error(function (data) {
                    $btn.removeClass('disabled');
                    notify(data.message, 3);
                });
            };
            $scope.cancel = function () {
                $modalInstance.dismiss('cancel');
            };
        }]);
        app.controller('ActivityController', ['$scope', '$compile', '$timeout','$http','ngModal', function ($scope, $compile, $timeout,$http,ngModal) {
            // ================================================
            $scope.activity_id =  '{{ $activity['id'] }}';
            //图片上传配置
            $scope.fileConfig = {
                config: {
                    language: 'zh',
                    maxFileCount: 1,
                    maxFileSize: 200,
                },
            }
            $scope.channel = {
                app: {
                    is_open: 'off',
                    app_urls: []
                },
                wechat: {
                    is_open: 'off',
                    qr_code: []
                }
            }
            $scope.isAuthorize = -1;//是否授权
            $scope.authorize = {};//授权信息
            function requestAuthorize(){
                $http({
                    method:'get',
                    url: '/web-api/configurations/wechat',
                    headers: JSON.parse($('meta[name="profile"]').attr('content')),
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                }).success(function (data) {
                    if (data.code == 200) {
                        if(data.data&&data.data['app_id']&&data.data['app_secret']&&data.data['group_code']){
                            $scope.isAuthorize = 1;
                            $scope.authorize = data.data;
                        }else{
                            $scope.isAuthorize = 0;
                        }
                    } else {
                        notify(data.message, 3);
                        $scope.isAuthorize = 0;
                    }
                }).error(function (data) {
                    notify(data.message, 3);
                });
            }
            requestAuthorize();
            function requestChannel(){
                $http({
                    method:'get',
                    url: '/web-api/publishing/'+$scope.activity_id,
                    headers: JSON.parse($('meta[name="profile"]').attr('content')),
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                }).success(function (data) {
                    if (data.code == 200) {
                        $scope.channel = {
                            app: {
                                is_open: data.data.app['is_open']?data.data.app['is_open']:'off',
                                app_urls: data.data.app['app_urls']?data.data.app['app_urls']:[]
                            },
                            wechat: {
                                is_open: data.data.wechat['is_open']?data.data.wechat['is_open']:'off',
                                qr_code: data.data.wechat['qr_code']?data.data.wechat['qr_code']:[]
                            }
                        }
                        $scope.refresh  = true;
                    } else {
                        notify(data.message, 3);
                    }
                }).error(function (data) {
                    notify(data.message, 3);
                });
            }
            @if(!empty($activity->id))
            requestChannel();
            @endif
            function createChannel(callback){
                $http({
                    method:'POST',
                    url: '/web-api/publishing/'+$scope.activity_id,
                    headers: JSON.parse($('meta[name="profile"]').attr('content')),
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                    data: $scope.channel
                }).success(function (data) {
                    if (data.code == 200) {
                        callback();
                    } else {
                        notify(data.message, 3);
                    }
                }).error(function (data) {
                    notify(data.message, 3);
                });
            }
            $scope.toggleClass = function($event,type){
                if($scope.isAuthorize!=1){
                    bootbox.confirm({
                        title: '提示:',
                        message: "您还未授权公众号，是否现在授权？",
                        buttons: {
                            confirm: {
                                label: '确认',
                                className: 'btn-success'
                            },
                            cancel: {
                                label: '取消',
                                className: 'btn-danger'
                            }
                        },
                        callback: function (result) {
                            if(result){
                                ngModal({
                                    templateUrl: '/components/addSubscription.html',
                                    controller: 'subscriptionModalController',
                                    resolve: {
                                        items: function () {
                                            return {
                                                isAuthorize: $scope.isAuthorize,
                                                authorize: $scope.authorize
                                            };
                                        }
                                    },
                                    ok: function (authorize) {
                                        $scope.channel.wechat.is_open = 'on';
                                        $scope.isAuthorize = 1;
                                    },
                                    cancel: function () {

                                    }
                                });
                            }
                        }
                    });
                }else{
                    if(type=='label'){
                        if($scope.channel.wechat.is_open=='on'){
                            $scope.channel.wechat.is_open = 'off';
                        }else{
                            $scope.channel.wechat.is_open = 'on';
                        }
                    }else{
                        $scope.channel.wechat.is_open = type;
                    }
                }
            }
            // ================================================

            @if(!empty($activity->id))
                $scope.activity = {
                name: '{{$activity->name}}',
                template: '',
                category: '{{$activity->category}}',
                basic: null,
                specs: null,
                prizes: null,
                preview_src: "/{{$activity->model->rule}}/activity/preview/{{$activity->model->rule}}/{{$activity->template->template}}",
                previewData: {},
                {{--share:{!! $share !!}--}}
            };
            var tpl = $('a[data-template="{{$activity->template_id}}"]').data('detail');
            if (tpl.isBackgroundImage == 1) {
                $('.backgroundImg-container').show();
            } else {
                $('.backgroundImg-container').hide();
            }
                    @else
            var isBackgroundImage = {{$ativity_template->isBackgroundImage}};
            $scope.activity = {
                name: '',
                template: '',
                category: '',
                basic: null,
                specs: null,
                prizes: null,
                preview_src: "/{{$ativity_model->rule}}/activity/preview/{{$ativity_model->rule}}/{{$ativity_template->template}}",
                previewData: {},
                {{--share:{!! $share !!}--}}
            };
            if (isBackgroundImage == 1) {
                $('.backgroundImg-container').show();
            } else {
                $('.backgroundImg-container').hide();
            }
            @endif

                    @if(!empty($activity->model_id))
                $scope.activity.previewData = {
                'background': '{{$activity->backgroundImg}}'
            };
            $scope.activity.preview_src = "/{{$activity->model->rule}}/activity/preview/{{$activity->model->rule}}/{{$activity->template->template}}"
            @else
                $scope.activity.preview_src = "/{{$ativity_model->rule}}/activity/preview/{{$ativity_model->rule}}/{{$ativity_template->template}}"
            @endif

                $scope.previewDataFunc = function () {
                return JSON.stringify($scope.activity.previewData);
            };
            /**
             * @desc 上传活动背景图，试图浏览
             * @param result
             * @param input_name
             */
            window.uploadFilesSuccess = function (result, input_name) {
                if (input_name == 'backgroundImg') {
                    $timeout(function () {
                        console.log($scope.activity);
                        $scope.activity.previewData['background'] = result.url;
                    })
                }
            };


            $scope.$watch('previewDataFunc()', function (newData) {
                if (newData) {
                    newData = JSON.parse(newData);
                    $urlPath = parseURL($scope.activity.preview_src);
                    $scope.activity.preview_src = $urlPath['path'] + '?' + $.param(newData);
                }
            });
            /*
            * 内容设置验证
            */
            $scope.onFinishContent = function () {
                tinyMCE.triggerSave();
                if (valideContentSet()) {
                    //激活下一个设置选项卡
                    $('.enroll-ul>li').removeClass('active');
                    $('.enroll-ul>li').eq(1).removeClass('disabled').addClass('active');
                    $('#activity_tab_0').removeClass('active');
                    $('#activity_tab_1').addClass('active');
                }
            };

            function valideContentSet() {
                var form = $('#activityForm');
                if (!form.find('input[name=name]').val()) {
                    utils.showNotification('请输入活动名称', 3);
                    return false;
                }
                if (form.find('input[name=name]').val()&&form.find('input[name=name]').val().length>20) {
                    utils.showNotification('活动名称最多不超过20个字符', 3);
                    return false;
                }
                if (!form.find('input[name=startTime]').val()) {
                    utils.showNotification('请输入活动开始时间', 3);
                    return false;
                }
                if (!form.find('input[name=endTime]').val()) {
                    utils.showNotification('请输入活动结束时间', 3);
                    return false;
                }
                if (moment(form.find('input[name=endTime]').val()).unix() < moment(form.find('input[name=startTime]').val()).unix()) {
                    utils.showNotification('活动结束时间不能小于开始时间', 3);
                    return false;
                }
                if (!form.find('textarea[name="description"]').val()) {
                    utils.showNotification('请输入活动介绍', 3);
                    return false;
                }
                return true;
            }

            /**
             * 报名设置验证提交
             * */
            $scope.onFinishEnroll = function () {
                if (valideEnrollSet()) {
                    //激活下一个设置选项卡
                    $('.enroll-ul>li').removeClass('active');
                    $('.enroll-ul>li').eq(2).removeClass('disabled').addClass('active');
                    $('#activity_tab_1').removeClass('active');
                    $('#activity_tab_2').addClass('active');
                }
            };

            function valideEnrollSet() {

//                if ($('input[name="rule[enrollPayOn]"]').val()==1&&!$('.input-enroll-pay').val()){
                if ($('#switch-enroll-pay').bootstrapSwitch('status') && !$('.input-enroll-pay').val()) {
                    utils.showNotification('请输入活动费用', 3);
                    return false;
                } else if ($('#switch-enroll-pay').bootstrapSwitch('status') && $('.input-enroll-pay').val() < 0) {
                    utils.showNotification('请输入大于等于0的有效数字', 3);
                    return false;
                }

//                if ($('input[name="rule[upContentOn]"]').val()==1&&$("input:radio[name='rule[upContentType]']:checked").length==0){
                if ($('#switch-enroll-upload').bootstrapSwitch('status') && $("input:radio[name='rule[upContentType]']:checked").length == 0) {
                    utils.showNotification('请选择上传类型', 3);
                    return false;
                }


                //            if($('input[name="rule[upContentOn]"]').val()==1&&!$('.input-enroll-upload').val()){
                if ($('#switch-enroll-upload').bootstrapSwitch('status') && !$('.input-enroll-upload').val()) {
                    utils.showNotification('请输入上传数量', 3);
                    return false;
                } else if ($('#switch-enroll-upload').bootstrapSwitch('status') && $('.input-enroll-upload').val() < 1) {
                    utils.showNotification('上传数量最小为1', 3);
                    return false;
                }
//                if ($("input:checkbox[name='']:checked").length==0){
//                    utils.showNotification('请选择默认字段',3);
//                    return false;
//                }
                var flag = 0;

                $('.vote-group-form').each(function () {
                    var stay = 0;
                    $(this).find('input').each(function () {
//                            alert('input:'+$(this).val());
                        if ($(this).val() == '') {
                            stay = 1;
//                                alert('stay:'+stay);
                            return false;
                        }
                    });
                    if (stay == 1) {
                        flag = 1;
                        return false;
                    }
                });

                if (flag == 1) {
                    utils.showNotification('请将自定义字段填写完整或删除不需要的字段', 3);
                    return false;
                }
                return true;
            }

            $scope.onFinishConfig = function(){
                if(valideEnrollConfig()){
                    $('.enroll-ul>li').removeClass('active');
                    $('.enroll-ul>li').eq(3).removeClass('disabled').addClass('active');
                    $('#activity_tab_2').removeClass('active');
                    $('#activity_tab_3').addClass('active');
                }
            }
            function valideEnrollConfig() {
                var url = $('input.app_url').val();

                if($scope.channel.app.is_open=='on'||$scope.channel.app.is_open=='1'){
                    if(!url){
                        utils.showNotification('请输入app下载地址', 3);
                        return false;
                    }
                    if(url&& !/^((https|http|ftp|rtsp|mms)?:\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(url)){
                        utils.showNotification('请输入正确的链接（例如：http://www.chinamcloud.com）', 3);
                        return false;
                    }
                }

                if($('#switch-enroll-share').bootstrapSwitch('status')){
                    if (!$('.input-enroll-self-title').val()) {
                        utils.showNotification('请将输入分享标题', 3);
                        return false;
                    }
                    console.log($('.input-enroll-self-title').val());
                    if ($('.input-enroll-self-title').val().length > 15) {
                        utils.showNotification('分享标题最多为15个字符', 3);
                        return false;
                    }
                    if (!$('.input-enroll-self-inf').val()) {
                        utils.showNotification('请输入分享文案', 3);
                        return false;
                    }
                    if ($('.input-enroll-self-inf').val().length > 50) {
                        utils.showNotification('分享文案最多为50个字符', 3);
                        return false;
                    }
                }
                return true;
            }
            /**
             * @desc 自定义设置验证，并提交
             */
            $scope.onFinishSelf = function () {
                if (valideSelfForm()) {
//                    createChannel(function(){
////                        location.href = '/web/activity/index';
//                    });
//                    var channelobj = $.param($scope.channel);
                    var obj = $('#activityForm').serialize();
                    $.isLoading({text: '数据提交中，请稍后。。。'});
                    $.post(location.href, obj, function (res) {
                        $.isLoading('hide');
                        if (res.code == 0) {
                            var notify = utils.showNotification('保存成功', 2);
                            setTimeout(function () {
                                window.location.href = "/web/activity/index";
                            }, 2000);
                        } else {
                            utils.showNotification(res.message, 3);
                        }
                    });

                }
            };

            function valideSelfForm() {
                return true;
            }

        }]);

        angular.bootstrap(document, ['app']);
    });

    /*导航点击事件*/
    $('.enroll-ul>li').click(function () {
        if ($(this).attr('class') == 'disabled') {
            if ($(this).index() == 1) {
                utils.showNotification('请先将内容设置保存！', 3);
                return false;
            } else if ($(this).index() == 2) {
                utils.showNotification('请先将报名设置保存！', 3);
                return false;
            }
        }
    });
    /*报名设置*/
    $('#switch-mul-enroll').bootstrapSwitch();

    if ('{{$rule["repeatedOn"]}}' == 'on') {
        $('#switch-mul-enroll').bootstrapSwitch('setState', true);
    }


    $('#switch-enroll-pay').bootstrapSwitch();

    if ('{{$rule["enrollPayOn"]}}' == 'on') {
        $('#switch-enroll-pay').bootstrapSwitch('setState', true);
        $('.div-enroll-pay').css('display', 'block');
        $('.input-enroll-pay').val('{{$rule["enrollPay"]}}');
//        $('#switch-enroll-pay').bootstrapSwitch('setState', true);
    }

    $('#switch-enroll-pay').on('switch-change', function (e, data) {
        if (data.value) {
            $('.div-enroll-pay').css('display', 'block');
//            $('input[name="rule[enrollPayOn]"]').val(1);
            $('#switch-enroll-pay').bootstrapSwitch('setState', true);
        } else {
            $('.div-enroll-pay').css('display', 'none');
//            $('input[name="rule[enrollPayOn]"]').val(0);
            $('#switch-enroll-pay').bootstrapSwitch('setState', false);
        }
    });
    $('#switch-enroll-upload').bootstrapSwitch();

    if ('{{$rule["upContentOn"]}}' == 'on') {
        $('#switch-enroll-upload').bootstrapSwitch('setState', true);

        $('.div-enroll-upload').css('display', 'block');

        if ('{{$rule["upContentType"]}}' == 'image') {
            $(".div-enroll-upload .enroll-upload-picture").attr("checked", 'checked');
        } else if ('{{$rule["upContentType"]}}' == 'video') {
            $(".div-enroll-upload .enroll-upload-video").attr("checked", 'checked');
        } else {
            $(".div-enroll-upload .enroll-upload-audio").attr("checked", 'checked');
        }

        $('.div-enroll-upload .input-enroll-upload').val('{{$rule["upContentNum"]}}');

    }

    $('#switch-enroll-number-show').bootstrapSwitch();
    if ('{{$rule["showEnrollNumberOn"]}}' == 'on') {
        $('#switch-enroll-number-show').bootstrapSwitch('setState', true);
    }

    $('#switch-enroll-upload').on('switch-change', function (e, data) {
        if (data.value) {
            $('.div-enroll-upload').css('display', 'block');
//            $('input[name="rule[upContentOn]"]').val(1);
            $('#switch-enroll-upload').bootstrapSwitch('setState', true);
        } else {
            $('.div-enroll-upload').css('display', 'none');
//            $('input[name="rule[upContentOn]"]').val(0);
            $('#switch-enroll-upload').bootstrapSwitch('setState', false);
        }
    });
    //自定义字段事件
    //添加自定义字段
    var typeName = {'radio': '单选', 'select': '多选', 'selectdown': '下拉', 'text': '单行文本', 'textarea': '多行文本','upload': '上传'};
    $('.add-vote-group-butten').click(function () {
        if (!$('input[name="enroll-self-type"]:checked').val()) {
            utils.showNotification('请选择要添加的自定义字段类型！', 3);
            return false;
        }
        var selfType = $('input[name="enroll-self-type"]:checked').val();
        var addObj;
        var html;
        if ($('.enroll-self-group').find('input[name="panduan[type][' + selfType + ']"]').length == 0) {
            addObj = $(this).closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';
            if (selfType == "text" || selfType == "upload" || selfType == "textarea") {
                html += '<div class="card vote-group-form" data-index=1>' +
                    '<div class="content">' +
                    '<div class="row">' +
                    '<div class="col-md-12 col-sm-12">' +
                    '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                    '</div>' +
                    '<div class="form-group">' +
                    '<label class="col-md-1 col-sm-1 control-label">01</label>' +
                    //                                    '<input name="rule['+selfType+'][01][index]" value="1" type="hidden">'+
                    '<div class="col-md-7 col-sm-7">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][01][value]" placeholder="请输入字段名称" data-msg="请输入字段名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<label class="checkbox-inline">' +
                    '<input type="checkbox" name="rule[' + selfType + '][01][must]" class=""> 必填项' +
                    '</label>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            } else {
                html += '<div class="card vote-group-form" data-index=1>' +
                    '<div class="content">' +
                    '<div class="row">' +
                    '<div class="col-md-12 col-sm-12">' +
                    '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                    '</div>' +
                    '<div class="form-group">' +
                    '<label class="col-md-1 col-sm-1 control-label">01</label>' +
                    '<input name="panduan[' + selfType + '][index]" value="1" type="hidden">' +
                    '<div class="col-md-6 col-sm-6">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][01][value]"  placeholder="请输入字段名称" data-msg="请输入字段名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<a class="btn btn-info add-enroll-group-option-btn" date-type="' + selfType + '" data-groupnum="01">添加选项</a>' +
                    '</div>' +
                    '<div class="col-sm-3 col-md-3 pull-center">' +
                    '<label class="checkbox-inline">' +
                    '<input type="checkbox" name="rule[' + selfType + '][01][must]"> 必填项' +
                    '</label>' +
                    '</div>' +
                    '</div>' +
                        {{--选项--}}
                            '<div class="enroll-self-option-form">' +
                    '<div class="enroll-self-option form-group" data-item=1>' +
                    '<label class="col-md-2 col-sm-2 col-md-offset-1 col-sm-offset-1 control-label">' +
                    '选项1' +
                    '</label>' +
                    //                                        '<input name="rule['+selfType+'][option][index]" value="1" type="hidden">'+
                    '<div class="col-md-5 col-sm-5">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][01][option][1]" placeholder="请输入选项名称" data-msg="请输入选项名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<button class="btn btn-info delet-enroll-group-option">删除选项</button>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            }
            addObj.before(html);
        } else {
            var addDom = '.enroll-self-' + selfType + '-form';
            addObj = $(addDom);
            var preIndex = $(addDom).children('.vote-group-form').last().data('index');
            var currentIndex;
            preIndex = parseInt(preIndex);
            if (preIndex < 10) {
                currentIndex = '0' + (preIndex + 1);
            } else {
                currentIndex = preIndex + 1;
            }
            if (selfType == "text" || selfType == "upload" || selfType == "textarea") {
                html = '<div class="card vote-group-form" data-index=' + (preIndex + 1) + '>' +
                    '<div class="content">' +
                    '<div class="row">' +
                    '<div class="col-md-12 col-sm-12">' +
                    '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                    '</div>' +
                    '<div class="form-group">' +
                    '<label class="col-md-1 col-sm-1 control-label">' + currentIndex + '</label>' +
                    //                                    '<input name="rule['+selfType+'][index]" value="'+(preIndex+1)+'" type="hidden">'+
                    '<div class="col-md-7 col-sm-7">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][' + currentIndex + '][value]" placeholder="请输入字段名称" data-msg="请输入字段名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<label class="checkbox-inline">' +
                    '<input type="checkbox" name="rule[' + selfType + '][' + currentIndex + '][must]" class=""> 必填项' +
                    '</label>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            } else {
                html = '<div class="card vote-group-form" data-index=' + (preIndex + 1) + '>' +
                    '<div class="content">' +
                    '<div class="row">' +
                    '<div class="col-md-12 col-sm-12">' +
                    '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                    '</div>' +
                    '<div class="form-group">' +
                    '<label class="col-md-1 col-sm-1 control-label">' + currentIndex + '</label>' +
                    '<input name="panduan[' + selfType + '][index]" value="' + (preIndex + 1) + '" type="hidden">' +
                    '<div class="col-md-6 col-sm-6">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][' + currentIndex + '][value]"  placeholder="请输入字段名称" data-msg="请输入字段名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<a class="btn btn-info add-enroll-group-option-btn" data-type="' + selfType + '" data-groupnum="' + currentIndex + '">添加选项</a>' +
                    '</div>' +
                    '<div class="col-sm-3 col-md-3 pull-center">' +
                    '<label class="checkbox-inline">' +
                    '<input type="checkbox" name="rule[' + selfType + '][' + currentIndex + '][must]"> 必填项' +
                    '</label>' +
                    '</div>' +
                    '</div>' +
                        {{--选项--}}
                            '<div class="enroll-self-option-form">' +
                    '<div class="enroll-self-option form-group" data-item=1>' +
                    '<label class="col-md-2 col-sm-2 col-md-offset-1 col-sm-offset-1 control-label">' +
                    '选项1' +
                    '</label>' +
                    //                                        '<input name="rule['+selfType+'][option][index]" value="1" type="hidden">'+
                    '<div class="col-md-5 col-sm-5">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][' + currentIndex + '][option][1]"  placeholder="请输入选项名称" data-msg="请输入选项名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<button class="btn btn-info delet-enroll-group-option">删除选项</button>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            }
            addObj.append(html);
        }
    });
    //删除自定义字段
    $('.enroll-self-group').on('click', '.vote_group_card_delet', function () {
        if ($(this).closest('.vote-group-card').children('.vote-group-form').length == 1) {
            $(this).closest('.vote-group-card').remove();
        } else {
            $(this).parents('.vote-group-form').remove();
        }
    });

    //添加选项事件
    $('.enroll-self-group').on('click', '.add-enroll-group-option-btn', function () {


        var selfType = $('input[name="enroll-self-type"]:checked').val();
//        alert(selfType);
        if (!selfType) {
            selfType = $(this).attr('data-type');
        }

//        var groupNum = $('.enroll-self-group').find('input[name="panduan['+selfType+'][index]"]').length;
        var groupNum = $(this).attr('data-groupnum');

        groupNum = parseInt(groupNum);

//        alert(groupNum);

        if (groupNum < 10) {
            groupNum = '0' + groupNum;
        }

        var obj = $(this).closest('.form-group').next().children('.enroll-self-option').last();
        var preIndex = obj.data('item');

        //        var currentIndex=preIndex+1;
        var currentIndex = $(this).closest('.row').find('.enroll-self-option').length + 1;
        var s = '<div class="enroll-self-option form-group" data-item=' + currentIndex + '>' +
            '<label class="col-md-2 col-sm-2 col-md-offset-1 col-sm-offset-1 control-label">' +
            '选项' + currentIndex +
            '</label>' +
            '<input name="panduan[' + selfType + '][option][index]" value="' + currentIndex + '" type="hidden">' +
            '<div class="col-md-5 col-sm-5">' +
            '<input class="form-control" type="text" name="rule[' + selfType + '][' + groupNum + '][option][' + currentIndex + ']"  placeholder="请输入选项名称" data-msg="请输入选项名称" />' +
            '</div>' +
            '<div class="col-sm-2 col-md-2">' +
            '<button class="btn btn-info delet-enroll-group-option">删除选项</button>' +
            '</div>' +
            '</div>';
        obj.after(s);
    });

    //删除选项事件
    $('.enroll-self-group').on('click', '.delet-enroll-group-option', function () {
        var $form = $(this).closest('.enroll-self-option-form');
        var $option = $form.children('.enroll-self-option');
        if ($option.length == 1) {
            return false;
        }
        $(this).parents('.enroll-self-option').remove();
        $form.children('.enroll-self-option').each(function (i, item) {
            $(this).find('.control-label').text('选项' + (i + 1));
        });
    });

    //分组设置索引
    function initialVoteGroup(preIndex) {
        var obj = $(".vote-group-form[data-index=" + preIndex + "]").next();
        var optIndex = preIndex + 1;
        obj.attr('data-index', optIndex);
    }

    /*自定义设置选项卡*/
    $('#switch-enroll-share').bootstrapSwitch();

    if ('{{$share["isopen"]}}' == 'on') {
        $('#switch-enroll-share').bootstrapSwitch('setState', true);
        $('.div-enroll-self').css('display', 'block');

        $('.input-enroll-self-title').val('{{$share["title"]}}');
        $('.input-enroll-self-inf').val('{{$share["content"]}}');

    }

    $('#switch-enroll-share').on('switch-change', function (e, data) {
        if (data.value) {
            $('.div-enroll-self').css('display', 'block');
//            $('input[name="share[isopen]"]').val(1);
            $('#switch-enroll-share').bootstrapSwitch('setState', true);

        } else {
            $('.div-enroll-self').css('display', 'none');
//            $('input[name="share[isopen]"]').val(0);
            $('#switch-enroll-share').bootstrapSwitch('setState', false);
        }
    });

    //渲染自定义字段
    var defaultField = {!! json_encode($rule) !!};


    initEditDefaultField(defaultField);

    function initEditDefaultField(defaultField) {


        //当前要遍历的类型
        var selfType = null;

        if (defaultField.upload) {

            selfType = 'upload';

            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';

            $.each(defaultField.upload, function (index, content) {
                html += textUpload(selfType, index, content);

            });

            html += '</div>';

            addObj.before(html);
        }

        if (defaultField.text) {

            selfType = 'text';
            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';

            $.each(defaultField.text, function (index, content) {
                html += textUpload(selfType, index, content);

            });
            html += '</div>';

            addObj.before(html);
        }
        if (defaultField.textarea) {

            selfType = 'textarea';
            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';

            $.each(defaultField.textarea, function (index, content) {
                html += textUpload(selfType, index, content);

            });
            html += '</div>';

            addObj.before(html);
        }

        if (defaultField.radio) {

            selfType = 'radio';

            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';

            $.each(defaultField.radio, function (index, content) {
                html += selectdownSelectRadio(selfType, index, content);

            });

            html += '</div>';
            addObj.before(html);

        }

        if (defaultField.select) {
            selfType = 'select';
            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';
            $.each(defaultField.select, function (index, content) {
                html += selectdownSelectRadio(selfType, index, content);

            });
            html += '</div>';
            addObj.before(html);
        }

        if (defaultField.selectdown) {
            selfType = 'selectdown';
            var addObj;
            var html;

            addObj = $('.add-vote-group-butten').closest('.enroll-self-group-addButton');
            html = '<div class="vote-group-card mb15 enroll-self-' + selfType + '-form">' +
                '<div class="pull-center">' +
                '<input name="panduan[type][' + selfType + ']" value="' + selfType + '" type="hidden">' +
                '<label>' + typeName[selfType] + '</label>' +
                '</div>';
            $.each(defaultField.selectdown, function (index, content) {

                html += selectdownSelectRadio(selfType, index, content);

            });
            html += '</div>';
            addObj.before(html);
        }


        function textUpload(selfType, index, content) {


            var must = content.must ? 'checked' : '';

            var html = '<div class="card vote-group-form" data-index=1>' +
                '<div class="content">' +
                '<div class="row">' +
                '<div class="col-md-12 col-sm-12">' +
                '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                '</div>' +
                '<div class="form-group">' +
                '<label class="col-md-1 col-sm-1 control-label">' + index + '</label>' +
                //                                    '<input name="rule['+selfType+'][01][index]" value="1" type="hidden">'+
                '<div class="col-md-7 col-sm-7">' +
                '<input class="form-control" type="text" name="rule[' + selfType + '][' + index + '][value]" placeholder="请输入字段名称" value="' + content.value + '" data-msg="请输入字段名称" />' +
                '</div>' +
                '<div class="col-sm-2 col-md-2">' +
                '<label class="checkbox-inline">' +
                '<input type="checkbox" name="rule[' + selfType + '][' + index + '][must]" ' + must + ' class=""> 必填项' +
                '</label>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            return html;
        }

        function selectdownSelectRadio(selfType, index, content) {

            var html;
            var must = content.must ? 'checked' : '';
            //option
            var option = '';
            var optionLength = 0;
            $.each(content.option, function (key, value) {


                option += '<div class="enroll-self-option form-group" data-item="' + key + '">' +
                    '<label class="col-md-2 col-sm-2 col-md-offset-1 col-sm-offset-1 control-label">' +
                    '选项' + key +
                    '</label>' +
                    //                             '<input name="rule['+selfType+'][option][index]" value="'+key+'" type="hidden">'+
                    '<div class="col-md-5 col-sm-5">' +
                    '<input class="form-control" type="text" name="rule[' + selfType + '][' + index + '][option][' + key + ']" value="' + value + '" placeholder="请输入选项名称" data-msg="请输入选项名称" />' +
                    '</div>' +
                    '<div class="col-sm-2 col-md-2">' +
                    '<button class="btn btn-info delet-enroll-group-option">删除选项</button>' +
                    '</div>' +
                    '</div>';
                optionLength = key;

            });

            html = '<div class="card vote-group-form" data-index=' + index + '>' +
                '<div class="content">' +
                '<div class="row">' +
                '<div class="col-md-12 col-sm-12">' +
                '<img src="/images/admin/delet_red.png" class="vote_group_card_delet pull-right mgb10 mgr30">' +
                '</div>' +
                '<div class="form-group">' +
                '<label class="col-md-1 col-sm-1 control-label">' + index + '</label>' +
                //                        '<input name="panduan['+selfType+'][index]" value="'+optionLength+'" type="hidden">'+
                '<div class="col-md-6 col-sm-6">' +
                '<input class="form-control" type="text" name="rule[' + selfType + '][' + index + '][value]" value="' + content.value + '" placeholder="请输入字段名称" data-msg="请输入字段名称" />' +
                '</div>' +
                '<div class="col-sm-2 col-md-2">' +
                '<a class="btn btn-info add-enroll-group-option-btn" data-type="' + selfType + '" data-groupnum="' + index + '">添加选项</a>' +
                '</div>' +
                '<div class="col-sm-3 col-md-3 pull-center">' +
                '<label class="checkbox-inline">' +
                '<input type="checkbox" name="rule[' + selfType + '][' + index + '][must]" ' + must + '> 必填项' +
                '</label>' +
                '</div>' +
                '</div>' +
                '<div class="enroll-self-option-form">' +

                //                        选项
                option +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';

            return html;
        }


    }

</script>